package com.ms.game.sendgift;

import java.util.ArrayList;
import java.util.HashMap;

import com.ms.game.itembox.Item;
import com.ms.game.itembox.db.PlayerItemModel;
import com.ms.game.itembox.message.SSimpleItem;
import com.ms.game.sendgift.db.SendGiftRecordLog;

public class NotifyData {

	public NotifyData(){
		
	}
	
	/**
	 * SendGiftRecordLog 轉成 NotifyData
	 * @param playerID
	 * @param model
	 */
	public NotifyData(String playerID, SendGiftRecordLog model, String stageList, ArrayList<PlayerItemModel> sendGiftItems) {
		
		if (playerID.toString().equals(model.getPlayerGUID())) {
			this.isSender = true;
		} else {
			this.isSender = false;
		}
		
		this.stage = model.getStage();
		
		String[] stageArray = stageList.split(",");
		this.stageList = new ArrayList<Integer>();
		for (int i = stageArray.length - 1; i >= 0; i--) {
			this.stageList.add(Integer.valueOf(stageArray[i]));
		}
		
		this.orderID = model.getSendOrderID();
		this.orderNumber = model.getOrderNumber();
		
		this.senderName = model.getPlayerName();
		this.targerName = model.getTargetName();
		
		this.goldCoin = model.getGoldCoin();
		this.charge = model.getServiceCharge();
		
		//道具
//		ArrayList<PlayerItemModel> sendGiftItems = ItemDAO.loadSendGiftItems(model.getOrderID());
		HashMap<String, SSimpleItem> items = new HashMap<String, SSimpleItem>();
		for (PlayerItemModel itemModel : sendGiftItems) {
			Item item = new Item(itemModel);
			items.put(item.getSn(), item.toClientFormat());
		}
		
		this.items = items;
		
		this.isFinish = model.isFinish();
		
		this.isSuccess = model.isSuccess();
		
		if (model.getCreateTime() == null) {
			this.createTime = 0L;
		} else {
			this.createTime = model.getCreateTime().getTime();
		}

		if (model.getAnswerTime() == null) {
			this.answerTime = 0L;
		} else {
			this.answerTime = model.getAnswerTime().getTime();
		}

		if (model.getCompleteTime() == null) {
			this.completeTime = 0l;
		} else {
			this.completeTime = model.getCompleteTime().getTime();
		}
		
		if (model.getFinalTakenTime() == null) {
			this.finalTakenTime = 0L;
		} else {
			this.finalTakenTime = model.getFinalTakenTime().getTime();
		}

		if(model.getSendbackTime() == null){
			this.sendBackTime = 0L;
		} else{
			this.sendBackTime = model.getSendbackTime().getTime();
		}
		
		if(model.getOutTakenTime() == null){
			this.outTakenTime = 0L;
		} else{
			this.outTakenTime = model.getOutTakenTime().getTime();
		}
		
		if(model.getOrderFinishTime() == null){
			this.orderFinishTime = 0L;
		}else{
			this.orderFinishTime = model.getOrderFinishTime().getTime();
		}
		
	}
	
	/**
	 * 送方 還是 收方
	 * true 送放
	 * false 收方
	 */
	public boolean isSender;
	
	/**
	 * 訂單ID (eventID)
	 */
	public long orderID;
	
	/**
	 * 交易序號顯示用
	 */
	public String orderNumber;
	
	/**
	 * 發送者名稱
	 */
	public String senderName;
	
	/**
	 * 接受者名稱
	 */
	public String targerName;
	
	/**
	 * 交易金錢
	 */
	public long goldCoin;
	
	/**
	 * 手續費
	 */
	public long charge;
	
	/**
	 * 道具<br>
	 * key: 道具序號<br>
	 * value: 道具資料
	 */
	public HashMap<String, SSimpleItem> items;
	
	/**
	 * 階段
	 */
	public int stage;
	
	/**
	 * 創建時間 (送方送出時間)
	 */
	public long createTime;
	
	/**
	 * 回答時間 (收方回應||送方取消)
	 */
	public long answerTime;
	
	/**
	 * 完成時間 (送方 打完密碼按下確定的時間)
	 */
	public long completeTime;
	
	/**
	 * 是否已結束
	 */
	public boolean isFinish;
	
	/**
	 * 交易成功還是失敗
	 */
	public boolean isSuccess;

	/**
	 * 頭像
	 */
	public String facePhoto;
	
	/**
	 * 東西是否已領取
	 */
	public boolean isTaken;
	
	
	/**
	 * 被退回的時間 (過期or客服退回)
	 */
	public long sendBackTime;

	/**
	 * 過期領取的時間
	 */
	public long outTakenTime;
	
	/**
	 * 此訂單最後領取的時間
	 */
	public long finalTakenTime;
	
	/**
	 * 訂單結束時間
	 */
	public long orderFinishTime;
	
	/**
	 * 此訂單的每個階段
	 */
	public ArrayList<Integer> stageList;
}
